package com.ruoyi.movie.controller;

import java.util.List;
import javax.servlet.http.HttpServletResponse;
import org.springframework.security.access.prepost.PreAuthorize;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.GetMapping;
import org.springframework.web.bind.annotation.PostMapping;
import org.springframework.web.bind.annotation.PutMapping;
import org.springframework.web.bind.annotation.DeleteMapping;
import org.springframework.web.bind.annotation.PathVariable;
import org.springframework.web.bind.annotation.RequestBody;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RestController;
import com.ruoyi.common.annotation.Log;
import com.ruoyi.common.core.controller.BaseController;
import com.ruoyi.common.core.domain.AjaxResult;
import com.ruoyi.common.enums.BusinessType;
import com.ruoyi.movie.domain.PubDate;
import com.ruoyi.movie.service.IPubDateService;
import com.ruoyi.common.utils.poi.ExcelUtil;
import com.ruoyi.common.core.page.TableDataInfo;

/**
 * 发行日期Controller
 *
 * @author ruoyi
 * @date 2025-01-29
 */
@RestController
@RequestMapping("/movie/pubDate")
public class PubDateController extends BaseController
{
    @Autowired
    private IPubDateService pubDateService;

    /**
     * 查询发行日期列表
     */
    @PreAuthorize("@ss.hasPermi('movie:pubDate:list')")
    @GetMapping("/list")
    public TableDataInfo list(PubDate pubDate)
    {
        startPage();
        List<PubDate> list = pubDateService.selectPubDateList(pubDate);
        return getDataTable(list);
    }

    /**
     * 导出发行日期列表
     */
    @PreAuthorize("@ss.hasPermi('movie:pubDate:export')")
    @Log(title = "发行日期", businessType = BusinessType.EXPORT)
    @PostMapping("/export")
    public void export(HttpServletResponse response, PubDate pubDate)
    {
        List<PubDate> list = pubDateService.selectPubDateList(pubDate);
        ExcelUtil<PubDate> util = new ExcelUtil<PubDate>(PubDate.class);
        util.exportExcel(response, list, "发行日期数据");
    }

    /**
     * 获取发行日期详细信息
     */
    @PreAuthorize("@ss.hasPermi('movie:pubDate:query')")
    @GetMapping(value = "/{pubDateId}")
    public AjaxResult getInfo(@PathVariable("pubDateId") Integer pubDateId)
    {
        return success(pubDateService.selectPubDateByPubDateId(pubDateId));
    }

    /**
     * 新增发行日期
     */
    @PreAuthorize("@ss.hasPermi('movie:pubDate:add')")
    @Log(title = "发行日期", businessType = BusinessType.INSERT)
    @PostMapping
    public AjaxResult add(@RequestBody PubDate pubDate)
    {
        return toAjax(pubDateService.insertPubDate(pubDate));
    }

    /**
     * 修改发行日期
     */
    @PreAuthorize("@ss.hasPermi('movie:pubDate:edit')")
    @Log(title = "发行日期", businessType = BusinessType.UPDATE)
    @PutMapping
    public AjaxResult edit(@RequestBody PubDate pubDate)
    {
        return toAjax(pubDateService.updatePubDate(pubDate));
    }

    /**
     * 删除发行日期
     */
    @PreAuthorize("@ss.hasPermi('movie:pubDate:remove')")
    @Log(title = "发行日期", businessType = BusinessType.DELETE)
	@DeleteMapping("/{pubDateIds}")
    public AjaxResult remove(@PathVariable Integer[] pubDateIds)
    {
        return toAjax(pubDateService.deletePubDateByPubDateIds(pubDateIds));
    }
}
